<?php
// +----------------------------------------------------------------------
// | 用户模块业务逻辑
// +----------------------------------------------------------------------
// | Author: myh
// +----------------------------------------------------------------------
namespace app\pc\service;
use app\common\model\UserModel;
use app\common\service\UserLevelService;

class PuserService
{   
    /**
     * 用户注册
     * @param  array  $data  新增的数据
     * @return int
     */
    public static function register($data){
        //验证该账号是否存在
        if(UserModel::getByAccount($data['account'])){
            serviceException(config('error.er8')['code'],config('error.er8')['msg']);
        }

        //验证手机号是否存在
        if(UserModel::getByMobile($data['mobile'])){
            serviceException(config('error.er9')['code'],config('error.er9')['msg']);
        }

        $level = UserLevelService::list();
        $data['level'] = empty($level) ? 0 : $level[0]['id'];

        $data['password'] = createPassword($data['password']);
        $user = new UserModel;
        $user->save($data);
        cache(config('cachekey.mobile_code').$data['mobile'],null);
        return $user->id;
    }

}
